package com.zhaolang.qogir.ui.adapter.manage;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.StringRes;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhaolang.qogir.R;
import com.zhaolang.qogir.bean.ManageAllComments;
import com.zhaolang.qogir.view.CircularImage;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ManageAllCommentAdapter extends BaseAdapter {
    private Context mContext;
    private List<ManageAllComments> comments;
    private String TAG = "ManageAllCommentAdapter";

    public ManageAllCommentAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void setData(List<ManageAllComments> comments) {
        this.comments = comments;
    }

    @Override
    public ManageAllComments getItem(int position) {
        return comments != null && position >= 0 & position < comments.size() ? comments
                .get(position) : null;
    }

    @Override
    public int getCount() {
        return comments != null ? comments.size() : 0;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        Log.d(TAG, "comment adapter position:" + position);
        ManageAllComments comments = getItem(position);
        final ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.ui_manage_all_comment_items, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (comments.getManageTvUserName().equals("")) {
            holder.manageTvUserName.setText("某某用户");
        } else {
            holder.manageTvUserName.setText(comments.getManageTvUserName());
        }
        holder.manageTvPackage.setText(comments.getManageTvPackage());
        holder.manageTvTaste.setText(comments.getManageTvTaste());
        holder.manageTvDelivery.setText(comments.getManageTvDelivery());
        holder.manageOrderTime.setText("2018/8/8 11:30");
        holder.manageTvCommentContents.setText(R.string.ui_manage_comment_msg);

        holder.manageTvOderSearch.setText("1231231552");
        holder.manageTvFeedback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                mContext.startActivity(new Intent(mContext, ActivityManageAllComment.class));
                Log.d(TAG, "manageTvFeedback click view");
            }
        });

        return convertView;
    }

    public class ViewHolder {
//        @BindView(R.id.manage_tv_user_name)
        TextView manageTvUserName;
//        @BindView(R.id.manage_tv_taste)
        TextView manageTvTaste;
//        @BindView(R.id.manage_tv_package)
        TextView manageTvPackage;
//        @BindView(R.id.manage_tv_delivery)
        TextView manageTvDelivery;
//        @BindView(R.id.manage_tv_comment_contents)
        TextView manageTvCommentContents;
//        @BindView(R.id.tv_manage_order_string_no)
        TextView tvManageOrderStringNo;
//        @BindView(R.id.manage_tv_order_no)
        TextView manageTvOrderNo;
//        @BindView(R.id.manage_tv_oder_search)
        TextView manageTvOderSearch;
//        @BindView(R.id.manage_order_time)
        TextView manageOrderTime;
//        @BindView(R.id.manage_tv_feedback)
        TextView manageTvFeedback;

        ViewHolder(View view) {
//            ButterKnife.bind(this, view);
            manageTvUserName = view.findViewById(R.id.manage_tv_user_name);
            manageTvTaste = view.findViewById(R.id.manage_tv_taste);
            manageTvPackage = view.findViewById(R.id.manage_tv_package);
            manageTvDelivery = view.findViewById(R.id.manage_tv_delivery);
            manageTvCommentContents = view.findViewById(R.id.manage_tv_comment_contents);
            tvManageOrderStringNo = view.findViewById(R.id.tv_manage_order_string_no);
            manageTvOrderNo = view.findViewById(R.id.manage_tv_order_no);
            manageTvOderSearch = view.findViewById(R.id.manage_tv_oder_search);
            manageOrderTime = view.findViewById(R.id.manage_order_time);
            manageTvFeedback = view.findViewById(R.id.manage_tv_feedback);
        }
    }
}
